<template>
  <div>
    <!-- <el-card class="mb20">
      <depart-form ref="departForm" @search="handleSearch" />
    </el-card>-->
    <el-card>
      <div style="text-align: right">
        <el-tooltip class="item" effect="dark" content="新增" placement="top">
          <el-button class="mb10" icon="el-icon-plus" type="primary" @click="handleAdd" />
        </el-tooltip>
      </div>
      <el-row :gutter="8">
        <el-col :span="5">
          <dept-tree :showSearch="true" ref="deptTree" @changeTree="handleChangeTree" />
        </el-col>
        <el-col :span="19">
          <department-table
            @setTree="handleSetTree"
            ref="departmentTable"
            @refresh="handleRefresh"
            @set="handleSet"
            @edit="handleEdit"
          />
        </el-col>
      </el-row>
      <set-modal ref="setModal" />
      <depart-modal ref="departModal" @refresh="handleRefresh" />
    </el-card>
  </div>
</template>

<script>
// import DepartForm from './DepartForm'
import DepartmentTable from './DepartTable'
import SetModal from './setModal'
import DepartModal from './DepartModal'
import DeptTree from '@/components/DeptTree'

export default {
  components: {
    // DepartForm,
    DepartmentTable,
    SetModal,
    DepartModal,
    DeptTree
  },
  name: 'DepartmentIndex',
  data() {
    return {
      selectObj: {}
    }
  },
  methods: {
    handleSetTree(row) {
      this.$refs.deptTree.getKeys([row.parentId])
      this.handleChangeTree(row)
    },
    handleSearch(param) {
      this.$refs.departmentTable.handleGetList(param)
    },
    handleChangeTree(obj) {
      this.selectObj = obj
      this.$refs.departmentTable.getId(obj)
    },
    // 设置岗位
    handleSet(record) {
      this.$refs.setModal.set(record)
    },
    // 新增
    handleAdd() {
      if (this.selectObj.parentId !== '') {
        this.$refs.departModal.edit(false, this.selectObj)
      } else {
        this.$refs.departModal.edit(false, {})
      }
    },
    // 编辑
    handleEdit(record) {
      if (this.selectObj.parentId !== '') {
        this.$refs.departModal.edit(true, { ...record, ...this.selectObj })
      } else {
        this.$refs.departModal.edit(true, record)
      }
    },
    // 刷新
    handleRefresh() {
      this.$refs.departmentTable.handleGetList()
      this.$refs.deptTree.refresh()
    }
  }
}
</script>


